/*
	依赖jquery
*/
var data = typeof(u)!='undefined'?'&uid='+u.uid+'&uname='+u.uname+'&uface='+u.face:'';
if(typeof(u)!='undefined' && u.uname)
{
	$('.comment > h4').append('(<font color=orange size=2>'+u.uname+'</font>)');
}
function answer(t,id)
{
	var html = '<dd class="answer"><form onsubmit="return false" action="" method="post"><textarea name="comment" id="answercmt" maxlength="140"></textarea><input type="submit" value="发送" onclick="send('+id+',this);" class="send"/><input type="reset" value="取消" onclick="unsend(this);" class="unsend"/></form></dd>';
	$('.answer').detach();
	$(t).parents('.say').after(html);
}
function unsend(t){$(t).parents('.answer').detach();}
function send(id, t)
{
	$.ajax({
	   type: "POST",
	   url: "ajax.php",
	   data: 'action=cmt&cid='+id+'&'+$(t).parents('form').serialize()+data,
	   success: function(msg){
		   var json = $.parseJSON(msg);
			json.res == 'OK'?($(t).parents('.answer').after(json.ifo),unsend(t)):alert(json.ifo);
	   }
	});
}
$('#answercmt').live('keyup',function(){
	var val = this.value;
	val?$('.send').show().siblings('input').hide():$('.unsend').show().siblings('input').hide();
})
function publish(t)
{
	$.ajax({
	   type: "POST",
	   url: "ajax.php",
	   data: 'action=cmt&'+$(t).parents('form').serialize()+data,
	   success: function(msg){
		   var json = $.parseJSON(msg);
			json.res == 'OK'?($('#comment-list').prepend(json.ifo),$('textarea').val(''),$('#nocmt').detach()):alert(json.ifo);
	   }
	});
}